package com.foo.ui_demo_widge;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;

public class CheckBoxActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check_box);

        CheckBox cbAgree = findViewById(R.id.cb_agree);
        Button btn_ch = findViewById(R.id.btn_ch);
        if (!cbAgree.isChecked()){
            btn_ch.setEnabled(false);
        }
        cbAgree.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    Toast.makeText(CheckBoxActivity.this
                    ,buttonView.getText(),Toast.LENGTH_SHORT).show();
                    btn_ch.setEnabled(true);

                }else {
                    btn_ch.setEnabled(false);
                }
            }
        });
    }
}